package com.shark.springbootcms.controller;

import com.shark.springbootcms.common.Result;
import com.shark.springbootcms.form.UserForm;
import com.shark.springbootcms.model.User;
import com.shark.springbootcms.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api
@RestController
@RequestMapping("/users")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/register")
    public Result register(@RequestBody User user) {
        return userService.register(user);
    }

    @PostMapping("/login")
    public Result login(@RequestBody User user) {
        return userService.login(user);
    }

    @GetMapping("/list")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",required = true,name = "page"),
            @ApiImplicitParam(paramType = "query",required = true,name = "pageSize"),
    })
    public Result list(UserForm form) {
        return userService.list(form);
    }

    @PostMapping("/add")
    public Result add(@RequestBody User user) {
        return userService.add(user);
    }

    @PostMapping("/edit/{id}")
    public Result edit(@RequestBody User user,@PathVariable("id") String id) {
        return userService.edit(user,id);
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable("id") String id) {
        return userService.delete(id);
    }

    @GetMapping("/roles")
    public Result roles() {
        return userService.roles();
    }



}
